package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.SystemMessage;
import cn.wolfcode.trip.base.mapper.SystemMessageMapper;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.ISystemMessageService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
@Service
public class SystemMessageServiceImpl implements ISystemMessageService {
    @Autowired
    private SystemMessageMapper systemMessageMapper;
    @Override
    public PageInfo query(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize(),qo.getOrderBy());
        List<SystemMessage> systemMessages = systemMessageMapper.queryForList(qo);
        return new PageInfo(systemMessages);
    }

    @Override
    public Integer getNoReadCount(Long userId) {
        return systemMessageMapper.getNoReadCount(userId);
    }

    @Override
    public void setRead(Long userId) {
        systemMessageMapper.setRead(userId);
    }

    @Override
    public void save(SystemMessage systemMessage) {
        systemMessage.setCreateTime(new Date());
        systemMessage.setState(false);
        systemMessageMapper.insert(systemMessage);
    }
}
